/**
 * 
 */
package com.xhis.system.print.web.actions;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.Blob;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;

import javax.servlet.http.HttpServletResponse;

import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.SessionScope;
import net.sourceforge.stripes.action.StreamingResolution;
import net.sourceforge.stripes.integration.spring.SpringBean;

import com.xhis.system.print.model.Result;
import com.xhis.system.print.service.PrintService;
import com.xhis.system.print.web.AbstractActionBean;

/**
 * @author lenovo
 * 
 */
public class PrintActionBean extends AbstractActionBean {

	private static final long serialVersionUID = 5499663666155758178L;

	private static final String PRINT = "/WEB-INF/jsp/print.jsp";

	private String fid;

	private Result result;

	private SortedMap printInfo;

	private SortedMap costAmtInfo;
	private transient String sign;
    public String getSign() {
		return sign;
	}
	public void setSign(String sign) {
		this.sign = sign;
	}

	private String time;
	public String getTime() {
		return time;
	}
	public void setTime(String time) {
		this.time = time;
	}
	public Result getResult() {
		return result;
	}

	public void setResult(Result result) {
		this.result = result;
	}

	public SortedMap getPrintInfo() {
		return printInfo;
	}

	public void setPrintInfo(SortedMap printInfo) {
		this.printInfo = printInfo;
	}

	public String getFid() {
		return fid;
	}

	public void setFid(String fid) {
		this.fid = fid;
	}

	@SpringBean
	private transient PrintService printService;

	@DefaultHandler
	public Resolution printInfo() throws Exception {
		toStoredMap1(printService.getPrintInfo(fid));
		result = new Result();
		this.result.setRows(printService.getPrintListInfo(fid));
		this.result.setRowCount(printService.getPrintListInfo(fid) == null ? -1
				: printService.getPrintListInfo(fid).size());
		toStoredMap2(printService.getTotalAMT(fid));

		return new ForwardResolution(PRINT);
	}

	private void toStoredMap1(Map map) {
		if (map != null) {
			SortedMap columnMap = new TreeMap(String.CASE_INSENSITIVE_ORDER);
			Set<Entry> entrySet = map.entrySet();
			for (Entry entry : entrySet) {
				columnMap.put(entry.getKey(), entry.getValue());
			}
			printInfo = columnMap;
		}

	}

	private void toStoredMap2(Map map) {
		if (map != null) {
			SortedMap columnMap = new TreeMap(String.CASE_INSENSITIVE_ORDER);
			Set<Entry> entrySet = map.entrySet();
			for (Entry entry : entrySet) {
				columnMap.put(entry.getKey(), entry.getValue());
			}
			costAmtInfo = columnMap;
		}

	}

	public void clear() {
		fid = null;
		printInfo = null;
	}

	public SortedMap getCostAmtInfo() {
		return costAmtInfo;
	}

	public void setCostAmtInfo(SortedMap costAmtInfo) {
		this.costAmtInfo = costAmtInfo;
	}

}
